package com.nep.NEPM.controller;

import com.nep.common.util.AlertUtil;
import com.nep.common.util.SceneSwitcherUtil;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

import java.util.Objects;

public class AdminLoginViewController {
    @FXML
    private Button btn_login;
    @FXML
    private TextField usernameField;
    @FXML
    private TextField passwordField;

    // 假设从配置文件或其他方式获取管理员凭据
    private static final String ADMIN_USERNAME = "01";
    private static final String ADMIN_PASSWORD = "01";

    public void Login(ActionEvent actionEvent) {
        String username = usernameField.getText();
        String password = passwordField.getText();

        // 验证输入是否为空
        if (username.isEmpty() || password.isEmpty()) {
            AlertUtil.showError("登录失败", "请输入用户名和密码");
            return;
        }

        if (Objects.equals(ADMIN_USERNAME, username) && Objects.equals(ADMIN_PASSWORD, password)) {
            // 登录成功，使用 SceneSwitcher 切换场景
            SceneSwitcherUtil.switchScene(btn_login,"/com/nep/NEPM/view/IndexView.fxml");
        } else {
            // 登录失败，使用 AlertUtil 显示错误信息
            AlertUtil.showError("登录失败", "用户名或密码错误！");
        }
    }
}